package org.vector.view;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import org.vector.daoImpl.BankDaoImpl;
import org.vector.test.Test;

@SuppressWarnings("serial")
public class WindowLoginVerify extends JFrame{
	BankDaoImpl bdi = new BankDaoImpl();
	private JTextField t1,t2;
	private JPasswordField ps;
	private JLabel l1,l2,l3,l4;
	private JPanel p,down;
	private JButton btn1,btn2;
	
	
	public WindowLoginVerify() {
		into();
		setVisible(true);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}

	private void into() {
		setSize(500, 600);
		setLocationRelativeTo(null);
		l1 = new JLabel("验证信息");
		add(l1,BorderLayout.NORTH);
		p = new JPanel();
		p.setLayout(null);
		l2 = new JLabel("请输入账号");
		t1 = new JTextField(20);
		l3 = new JLabel("银行卡号");
		t2 = new JTextField(20);
		l4 = new JLabel("银行卡支付密码");
		ps = new JPasswordField(20);
		
		l2.setBounds(50, 20, 100, 25);
		t1.setBounds(140, 20, 150, 25);
		l3.setBounds(50, 50, 100, 25);
		t2.setBounds(140, 50, 150, 25);
		l4.setBounds(50, 80, 100, 25);
		ps.setBounds(140, 80, 150, 25);
		
		p.add(l2);
		p.add(t1);
		p.add(l3);
		p.add(t2);
		p.add(l4);
		p.add(ps);
		add(p,BorderLayout.CENTER);
		
		down = new JPanel();
		btn1 = new JButton("取消");
		btn2 = new JButton("验证");
		down.add(btn1);
		down.add(btn2);
		add(down,BorderLayout.SOUTH);
		
		btn1.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				WindowLoginVerify.this.dispose();
				new Test();
			}
		});
		btn2.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				String bankid = t1.getText();
				int a = Integer.valueOf(bankid);
				
				String ccd = t2.getText();
				int b = Integer.valueOf(ccd);
				
				String pwd = new String(ps.getPassword());
				int c = Integer.valueOf(pwd);
				
				int d = bdi.yanzheng(a, b, c);
				if(d == 1) {
					WindowLoginVerify.this.dispose();//关闭当前窗口
					new Last(a);
				}else {
					new Wcuowu();
				}
			}
		});
	}
	
//	public static void main(String[] args) {
//		new WindowLoginVerify();
//	}
}
